package com.petsdar.controller;

import com.petsdar.service.PowerService;
import com.petsdar.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * Created with IntelliJ IDEA
 * User: heroC
 * Date: 2020/7/4
 * Time: 15:43
 * Description: power相关的controller层
 * Version: V1.0
 */

@RestController
public class PowerController {

    /** power相关的业务逻辑处理实例对象 */
    private PowerService powerService;

    @Autowired
    public void setPowerService(PowerService powerService) {
        this.powerService = powerService;
    }

    /**
     * 获取店长账户的权限信息
     * @return
     */
    @GetMapping("/keeperpower")
    public String getKeeperPower(){
        Map<String, Object> map = powerService.getKeeperPower();
        if (!map.isEmpty()){
            return ResultUtil.success(map);
        }
        return ResultUtil.fail();
    }

    /**
     * 更新店长账户的权限
     * @param powerJson 权限Json数据
     * @return
     */
    @PostMapping("/keeperpower")
    public String updateKeeperPower(@RequestBody String powerJson){
        boolean result = powerService.updateKeeperPower(powerJson);
        if (result){
            return ResultUtil.success();
        }
        return ResultUtil.fail();
    }
}
